package com.three.lab.base;

import android.content.Context;
import android.content.Intent;

import com.three.lab.MyApplication;
import com.three.lab.page.common.SplashActivity;
import com.three.lab.util.SharedPreferencesUtils;

public class AppManager {
    private AppManager() {
        throw new UnsupportedOperationException("can't instance…");
    }

    public static long getTimesTamp(){
        return System.currentTimeMillis();
    }

    public static void setSelectLanguage(int i){
        set(AppConstant.SELECTED_LANGUAGE,i);
    }

    public static int getSelectLanguage(Context context){
        return (int) SharedPreferencesUtils.getInstances(context).getSharedPreference(AppConstant.SELECTED_LANGUAGE,0);
    }

    public static void setHasEnter(boolean b){
        set(AppConstant.HAS_SUCCESS_ENTER,b);
    }

    public static boolean hasEnter(){
        return (boolean) SharedPreferencesUtils.getInstances(MyApplication.getContext()).getSharedPreference(AppConstant.HAS_SUCCESS_ENTER,false);
    }

    private static void set(String key, Object text) {
        SharedPreferencesUtils.getInstances(MyApplication.getContext()).put(key,text);
    }

    public static Object get(String key,Object obj){
        return SharedPreferencesUtils.getInstances(MyApplication.getContext()).getSharedPreference(key,obj);
    }


    public static void reLogin(final Context context){
        try {
            MyApplication.getInstances().removeAll();
            Intent intent = new Intent();
            intent.setClass(context, SplashActivity.class);
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            context.startActivity(intent);
            System.exit(0);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
